package nonpersisted

import enummpay.MessageType

/**
 * Created by IntelliJ IDEA.
 * User: TuarnOte
 * Date: 12/7/11
 * Time: 12:26 PM
 * To change this template use File | Settings | File Templates.
 */
class OzenkiRequest {
    String message
    String code
    Double amount
    Long transactionId
    String requestDetail
    Boolean isValidRequest = true

    OzenkiRequest(String message) {
        this.message = message
        String[] msg = this.message.split("\\*")

        // set code
        this.code = msg[1]

        // if the request is payment request
        // then set amount value
        if (this.code.equals(MessageType.PAYMENT.value())) {
            this.amount = msg[2].toDouble()

            // set seller's mobile
            String m = msg[3]
            this.requestDetail = m.substring(0, m.indexOf("#"))
        } else if (this.code.equals(MessageType.CONFIRM.value())) {
            // if the request is confirm request
            // then set transaction id
            this.transactionId = msg[2].toLong()

            // set pin
            String m = msg[3]
            this.requestDetail = m.substring(0, m.indexOf("#"))
        } else {
            // if the code is incorrect
            // then set isValidRequest = false
            this.isValidRequest = false
        }

    }

    MessageType getCode() {
        if (this.code.equals(MessageType.PAYMENT.value())) {
            return MessageType.PAYMENT
        } else if (this.code.equals(MessageType.CONFIRM.value())) {
            return MessageType.CONFIRM
        }

        return MessageType.PAYMENT;
    }

    String getMessage() {
        return message
    }

    void setMessage(String message) {
        this.message = message
    }


    Double getAmount() {
        return amount
    }

    Long getTransactionId() {
        return transactionId
    }

    String getRequestDetail() {
        return requestDetail
    }

    Boolean getIsValidRequest() {
        return isValidRequest
    }
}
